<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no,email=no" />
		<title>微店列表</title>
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link href="../css/style.css" rel="stylesheet" />
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<!--<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>-->
			<h1 class="mui-title">全部微店</h1>
		</header>
		
		<div id="pullrefresh" class="mui-content mui-scroll-wrapper transparent">
			<div class="mui-scroll">
				<h3 class="custom-title">微店社区</h3>
				<div id="VShops">
					
				</div>
			</div>
		</div>
		
		<script src="../js/mui.min.js"></script>
		<script src="../js/app.js"></script>
		<!--<script src="../js/delayimg.min.js"></script>-->
		<script>
			var isnodata = false,
				page = 1;
			mui.init({
				pullRefresh : {
				    container:'#pullrefresh',
				    deceleration:0.0006,
				    up : {
					    contentrefresh : "正在加载...",
					    contentnomore:'已加载全部微店',
					    callback :function(){
					      	var self=this;
					      	if (!isnodata) {
					      		page++;
						        mui.ajax(URL+'api/VShop/GetVShops?pageNo='+page+'&pageSize=10',{
									dataType:'json',
									type:'get',
									timeout:10000,
									success:function(data){
										if(data.Success=='true'){
						                    var vshops = '';
						                    for(var i=0; i<data.VShops.length; i++){
												vshops+='<div class="vshop-info">'+
													'<a class="vshop-url vshop-img" data-vshopid="'+data.VShops[i].id+'"><img src="'+data.VShops[i].image+'"  /></a>'+
													'<div class="vshop-info-text">';
														if(data.VShops[i].favorite)
															vshops+='<i data-shopid="'+data.VShops[i].shopId+'" class="addFavoriteShop iconfont icon-xin red"></i>';
														else
															vshops+='<i data-shopid="'+data.VShops[i].shopId+'" class="addFavoriteShop iconfont icon-xin"></i>';
														vshops+='<h3><a class="vshop-url" data-vshopid="'+data.VShops[i].id+'">'+data.VShops[i].name+'</a></h3><p>';
														if(data.VShops[i].tags!='')
															vshops+='<span>'+data.VShops[i].tags+'</span>';
														vshops+='</p>'+
													'</div>'+
												'</div>';
											}
											document.getElementById('VShops').insertAdjacentHTML('beforeend',vshops);
//											delayimg.render();
						                    if (data.Total<=page*10) {isnodata = true;}
											self.endPullupToRefresh(isnodata);
					      					
										}
									},
									error:function(xhr,type,errorThrown){
										plus.nativeUI.toast('请求失败，请检查网络')
									}
								});
						    }else{
						    	self.endPullupToRefresh(isnodata);
						    }
				    	}
				    }
				}
			});
			
			mui.plusReady(function() {
				var w=plus.nativeUI.showWaiting('',{padlock:true});
				mui.ajax(URL+'api/VShop/GetVShops?pageNo=1&pageSize=10',{
					dataType:'json',
					type:'get',
					timeout:10000,
					success:function(data){
						if(data.Success=='true'){
							var vshops='';
							if (data.Total<=10) {isnodata = true;}
							if(data.Total>0){
								for(var i=0; i<data.VShops.length; i++){
									vshops+='<div class="vshop-info">'+
										'<a class="vshop-url vshop-img" data-vshopid="'+data.VShops[i].id+'"><img src="'+data.VShops[i].image+'"  /></a>'+
										'<div class="vshop-info-text">';
											if(data.VShops[i].favorite)
												vshops+='<i data-shopid="'+data.VShops[i].shopId+'" class="addFavoriteShop iconfont icon-xin red"></i>';
											else
												vshops+='<i data-shopid="'+data.VShops[i].shopId+'" class="addFavoriteShop iconfont icon-xin"></i>';
											vshops+='<h3><a class="vshop-url" data-vshopid="'+data.VShops[i].id+'">'+data.VShops[i].name+'</a></h3><p>';
											if(data.VShops[i].tags!='')
												vshops+='<span>'+data.VShops[i].tags+'</span>';
											vshops+='</p>'+
										'</div>'+
									'</div>';
								}
								document.getElementById('VShops').innerHTML=vshops;
//								delayimg.init();
							}else{
								var html='<div class="empty-show"><h4>商城没有任何微店</h4><button id="closeWv" class="mui-btn mui-btn-negative">去其他地方逛逛</button></div>';
					        	document.getElementById('pullrefresh').innerHTML=html;
							}
							w.close();
							document.getElementById('pullrefresh').className='mui-content mui-scroll-wrapper';
						}
					},
					error:function(xhr,type,errorThrown){
						reloadWvLoad();
					}
				});
				
					
				mui('.mui-content').on('tap', '.vshop-url', function() {
					var vshopid = this.getAttribute('data-vshopid');
					
					showVshop(vshopid)
				});
				
				
				mui('.mui-content').on('tap', '.addFavoriteShop', function() {
					var _this=this;
					if(app.isLogin()){
						var w=plus.nativeUI.showWaiting('',{padlock:true});
						var shopid=_this.getAttribute('data-shopid');
						mui.ajax(URL+'api/VShop/PostAddFavoriteShop',{
							data:JSON.stringify({shopId:shopid}),
							dataType:'json',
							contentType:'application/json',
							type:'POST',
							timeout:10000,
							success:function(data){
								w.close();
								if(data.Success=="true"){
									plus.nativeUI.toast(data.Msg);
									if(_this.className.indexOf('red')>=0)
										_this.className='addFavoriteShop iconfont icon-xin';
									else
										_this.className='addFavoriteShop iconfont icon-xin red';
								}else{
									plus.nativeUI.toast('关注店铺失败');
								}
							},
							error:function(xhr,type,errorThrown){
								w.close();
								plus.nativeUI.toast('关注失败，请检查网络')
							}
						});
					}else{
						showLogin('/');
					}
					
				});
				
			});
			
		</script>
	</body>

</html>